<?php

namespace App\Service\Third;

use App\Model\OcpcTencent;
use App\Service\BaseService;

class TencentAdService extends BaseService
{
    //https://xxx.com/callback/tencent_ad?
    //?account_id=__ACCOUNT_ID__
    //&click_id=__CLICK_ID__
    //&click_time=__CLICK_TIME__
    //&device_os_type=__DEVICE_OS_TYPE__
    //&hash_android_id=__HASH_ANDROID_ID__
    //&muid=__MUID__
    //&hash_oaid=__HASH_OAID__
    //&promoted_object_id=__PROMOTED_OBJECT_ID__
    //&campaign_id=__CAMPAIGN_ID__
    //&adgroup_id=__ADGROUP_ID__
    //&ad_id=__AD_ID__
    //&ip=__IP__
    //&user_agent=__USER_AGENT__
    //&promoted_object_type=__PROMOTED_OBJECT_TYPE__
    //&callback=__CALLBACK__

    /**
     * @return int
     */
    public function handle(): int
    {
        $params = $this->request->all();

        log_info('腾讯广告监测链接===='.json_encode($params));

        if (OcpcTencent::existsOaid($params['hash_oaid'] ?? '')) {
            return 1;
        }

        if (OcpcTencent::existMuid($params['muid'] ?? '')) {
            return 1;
        }

        $ret = OcpcTencent::addLog($params);


        return $ret;
    }
}